package b4.view.component.smithy
{
	import b4.config.BasicObjConfig;
	import b4.config.Config;
	import b4.model.vo.player.BasicObj;
	import b4.model.vo.player.Equip;
	import b4.model.vo.player.Obj;
	import b4.view.component.pack.BasicObjItem;
	
	import org.aswing.JPanel;
	
	public class BaseTab extends JPanel
	{
		public var boxArr:Array;
		public var  tryToLoadRs:Object = new Object();
		public function BaseTab()
		{
			super();
			boxArr = new Array();
		}
		public function tryToLoadItem(obj:BasicObj):int
		{
			return 0;
		}
	    public function loadItem(obj:BasicObj):BoxObj
	    {
	    	var loadStatus:int;
	    	var boxReplace:BoxObj;
	    	var boxItem:BasicObjItem = new BasicObjItem(obj);
	    	boxItem.setNumTxtState(false);
	    	var returnBox:BoxObj;
	    	for (var i :int = 0; i < this.boxArr.length; i++)
	    	{	
	    		var boxObj:BoxObj = boxArr[i] as BoxObj;
				loadStatus = boxObj.loadObj(boxItem);
				if(loadStatus == BoxObj.STATUS_SUCCESS)
				{
					returnBox = boxObj;
					return returnBox
				}
				else if(loadStatus == BoxObj.STATUS_OCCUPIED)
				{
					if (boxReplace == null)
						boxReplace = boxObj;
				}
	    	}
		    if (boxReplace != null)
		    {
	    		boxReplace.loadObj(boxItem, true);
	    		returnBox = boxReplace as BoxObj;
		    }
		    return returnBox;
	    }
	    
	    public function getLoadedItems():Array
	    {
			var objList:Array = new Array();
			for (var i:int;i< boxArr.length;i++)
			{
				var boxObj:BoxObj = boxArr[i] as BoxObj;
				if (boxObj.hasObj)
					objList.push(boxObj.boxItem.obj)
			}
			return objList;
	    }
	    
	    public function loadOffAll():void
	    {
	    	for (var temStr :String in boxArr)
	    	{
	    		var boxObj :BoxObj = boxArr[temStr];
	    		if (boxObj.hasObj)
	    		{
	    			boxObj.loadOffItem();
	    		}
	    	}	    	
	    }
	    
	    public function  getSendData():Object
	    {
	    	var data:Object = {"equipList": {}, "objList": {}};
	    	for (var temStr:String in boxArr)
	    	{
	    		var boxObj:BoxObj = boxArr[temStr] as BoxObj;
	    		if (boxObj.hasObj)
	    		{
	    			var objConfig:BasicObjConfig = Config.objConfigs[boxObj.boxItem.obj.index];
		    		if (objConfig.type == BasicObjConfig.TYPE_EQUIP )
		    		{
		    			var equipObj:Equip = boxObj.boxItem.obj as Equip;
		    			data["equipList"][equipObj.id] = 1;
		    		}
		    		else
		    		{
		    			var obj:Obj = boxObj.boxItem.obj as Obj;
		    			if (data["objList"][obj.index] != null)
		    			{
		    				data["objList"][obj.index] += 1;
		    			}
		    			else
		    			{
		    				data["objList"][obj.index] = 1;
		    			}
		    		}
	    		}
	    	}
	    	return data;
	    }
	}
}
